//
//  HotDetailViewController.m
//  ZAKER
//
//  Created by dllo on 15/8/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "HotDetailViewController.h"


@interface HotDetailViewController ()<UIWebViewDelegate>


@property (nonatomic, retain) MBProgressHUD *mb;


@end


@implementation HotDetailViewController


-(void)dealloc
{
    
    
    [_mb release];
    [_urlStr release];
    
    [super dealloc];
    
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
//    UIWindow *window = [[[UIApplication sharedApplication]delegate]window];
    UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
    self.mb = [[MBProgressHUD alloc]initWithView:window];
    [window addSubview:_mb];
    _mb.labelText = @"正在加载";
    [_mb show:YES];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        
        if (_mb != nil) {
            
            [_mb removeFromSuperview];
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"数据加载失败" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert  show];
            [alert release];
        }
    });
    
    [self createWebView];

}
#pragma mark - 把webView的网址传过来

-(void)sendWithUrl:(NSURL *)urlStr
{
    
    self.urlStr = urlStr;
    
}

#pragma mark - 创建webView, 以及实现协议方法

-(void)createWebView
{
    
    UIWebView *web = [[[UIWebView  alloc]initWithFrame:CGRectMake(0, -49, self.view.frame.size.width, self.view.frame.size.height)] autorelease];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:self.urlStr];
    web.scalesPageToFit = YES;
    [web loadRequest:request];
    web.delegate = self;
    [self.view addSubview:web];
    [web release];

}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    
    [_mb hide:YES];
    _mb = nil;
    
}

- (void)didReceiveMemoryWarning
{
    
    [super didReceiveMemoryWarning];
   
}



@end
